﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace WorkNodeFramework
{
    public class SerializationService
    {
        public static object Deserialize(string base64String) {
            byte[] data = Convert.FromBase64String(base64String);
            MemoryStream ms =  new MemoryStream(data);
            BinaryFormatter bf = new BinaryFormatter();
            object result = bf.Deserialize(ms);
            ms.Dispose();
            return result;
        }

        public static string SerializeToBase64String(object obj) {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, obj);
            ms.Flush();
            string data = Convert.ToBase64String(ms.ToArray());
            ms.Dispose();
            return data;
        }
    }
}
